package com.ledim.activity.base;

import android.os.Bundle;
import android.widget.GridView;
import com.letv.android.young.client.R;
import com.ledim.widget.loadmore.LedimLoadMoreFooterView;
import com.ledim.widget.loadmore.LoadMoreContainer;
import com.ledim.widget.loadmore.LoadMoreGridViewContainer;
import com.ledim.widget.loadmore.LoadMoreHandler;

/**
 * Created by ccx on 16/8/10.
 * 可刷新GirdView
 */
public abstract class LedimBaseGridViewActivity<D>
        extends LedimBaseAdapterViewActivity<D, GridView> {

    protected LoadMoreGridViewContainer loadMoreContainer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mAdapterView.setNumColumns(getNumColumns());
    }

    protected abstract int getNumColumns();

    @Override
    protected void initFooterView() {
        loadMoreContainer = findViewByIdExt(R.id.loadmore_view_container);
        if (enableLoadMoreRefresh()) {
            // TODO 改为自定义的footer,或者修改arr中默认footer添加loading progressbar
            LedimLoadMoreFooterView footerView = new LedimLoadMoreFooterView(this);
            loadMoreContainer.setLoadMoreView(footerView);
            loadMoreContainer.setAutoLoadMore(true);
            loadMoreContainer.setLoadMoreUIHandler(footerView);
            loadMoreContainer.setLoadMoreHandler(new LoadMoreHandler() {
                @Override
                public void onLoadMore(LoadMoreContainer loadMoreContainer) {
                    loadMore();
                }
            });
        }
    }

    @Override
    protected void loadMoreFinish(int errorCode, boolean hasMore) {
        loadMoreContainer.loadMoreFinish(errorCode, hasMore);
    }

}
